<script>
export default {
  onLaunch(){
      // 全局方法挂载
      Date.prototype.$format = function(fmt) { 
        let o = { 
            "M+" : this.getMonth()+1,                 //月份 
            "d+" : this.getDate(),                    //日 
            "h+" : this.getHours(),                   //小时 
            "s+" : this.getSeconds(),                 //秒 
            "q+" : Math.floor((this.getMonth()+3)/3), //季度 
            "S"  : this.getMilliseconds()             //毫秒 
        }
        if(/(y+)/.test(fmt)) {
          fmt = fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
        }
        for(let k in o) {
            if(new RegExp("("+ k +")").test(fmt)){
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
            }
        }
        return fmt; 
      }        
      // 日期定制化/
      wx.$timeFormat = (fmt,type)=>{
        if(!fmt)return ''
        let date = new Date(fmt.replace(/-/g,'/'))
        if(type == 'time'){
          return date.$format('dd/MM/yyyy hh:ss')
        }else{
          return date.$format('dd/MM/yyyy')
        }
      }
      
  },
  onShow() {
    const updateManager = wx.getUpdateManager()
    updateManager.onCheckForUpdate(res => {
      // 请求完新版本信息的回调
      if (res.hasUpdate) {
        wx.showModal({
          title: '更新提示',
          content: '已有新的版本是否更新并重启？',
          showCancel: false,
          success: res => {
            if (res.confirm) {
              wx.showLoading({
                title: '应用重启中',
                mask: true
              })
              updateManager.onUpdateReady(() => {
                // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
                wx.hideLoading()
                updateManager.applyUpdate()
              })
              updateManager.onUpdateFailed(function() {
                // 新版本下载失败
                wx.hideLoading()
                wx.showModal({
                  // 新的版本下载失败
                  title: '已经有新版本了哟~',
                  content:
                    '新版本已经上线啦~，请您删除当前小程序，重新搜索打开哟~'
                })
              })
            }
          }
        })
      }
    })

    // 国际化
    let lang = wx.getSystemInfoSync().language
    // 无语种时预设一个默认语言
    if (!wx.getStorageSync('local')) {
      let localList = require('./utils/locales.js')
      if (lang == 'zh' || lang == 'zh_CN') {
        wx.setStorageSync('local', localList.localList.zh)
      } else {
        wx.setStorageSync('local', localList.localList.en)
      }
      wx.setStorageSync('lang', lang)
    }
  },
  onHide() {
    wx.setStorageSync('websocketFlag', false)
  },
  created() {
    // 调用API从本地缓存中获取数据
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // eslint-disable-next-line
  }
}
</script>
const app = getApp();
Page({
  data: {
    statusBarHeight: getApp().globalData.statusBarHeight,
  }
});
<style lang="scss">
/*@import  url(style/base.scss);*/
@import url(style/iconfont/iconfont.css);
page {
  height: 100%;
  width: 100%;
}
.container {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  /*padding: 200rpx 0;*/
  box-sizing: border-box;
}
/* this rule will be remove */
* {
  transition: width 2s;
  -moz-transition: width 2s;
  -webkit-transition: width 2s;
  -o-transition: width 2s;
}
</style>
